import Vue from "vue";
import Router from "vue-router";

Vue.use(Router);
import Layout from "@/layout";

/**
  *详情见:https://panjiachen.github.io/vue-element-admin-site/guide/essentials/router-and-nav.html
  * hidden: true                如果设置为true，项目将不会显示在侧边栏(默认为false)
  * alwaysShow: true            如果设置为true，将始终显示根菜单
                                如果没有设置alwaysShow，当item有多个子路由时，
                                它将成为嵌套模式，否则不显示根菜单
  * redirect: noRedirect        如果设置了noRedirect，则不会在面包屑中重定向
  * name:'router-name'          这个名字被<keep-alive>使用(必须设置!!)
  * meta: {
    parten:true                  如果设置为true 则表示为父级
    title:'Title'               名称显示在侧边栏和面包屑(建议设置)
    icon:'svg-name'/'el-icon-x' 图标显示在侧边栏
    noCache: true               如果设置为true，页面将不会被缓存(默认为false)
    affix:true                  标签将会被粘贴到标签视图中
    breadcrumb:false            如果设置为false，该项目将隐藏在面包屑中(默认为true)
    activeMenu:'/example/list'  如果设置了path，侧边栏会突出显示你设置的路径
  ｝
 */

/**
 * 没有权限要求的基本页面
 *所有角色都可以访问
 */
export const constantRoutes = [
  {
    path: "/login",
    component: () => import("@/views/login/index"),
    hidden: true,
  },
  {
    path: "/auth-redirect",
    component: () => import("@/views/login/auth-redirect"),
    hidden: true,
  },
  {
    path: "/404",
    component: () => import("@/views/404"),
    hidden: true,
  },
  {
    path: "/401",
    component: () => import("@/views/401"),
    hidden: true,
  },
  {
    path: "/",
    component: Layout,
    redirect: "/dashboard",
    children: [
      {
        path: "dashboard",
        name: "Dashboard",
        component: () => import("@/views/dashboard/index"),
        meta: { title: "控制台", icon: "dashboard", affix: true },
      },
    ],
  },

  // {
  //   path: '/icon',
  //   component: Layout,
  //   redirect: '/index',
  //   children: [{
  //     path: 'index',
  //     component: () => import('@/views/icons'),
  //     name: 'icon',
  //     meta: { title: '图标', icon: 'icon', affix: true }
  //   }]
  // }
];

/**
 * asyncRoutes需要根据用户角色动态加载的路由
 */
export const asyncRoutes = [
  // 统计管理
  {
    path: "/platformData",
    component: Layout,
    meta: { title: "统计管理", icon: "el-icon-s-shop", aCode: "/platformData" },
    children: [
      {
        path: "CountRecharge",
        name: "CountRecharge",
        component: () => import("@/views/platformData/CountRecharge/index"),
        meta: {
          title: "用户充值日统计",
          icon: "list",
          aCode: "/platformData/CountRecharge",
        },
      },
      {
        path: "RecordRecharge",
        name: "RecordRecharge",
        component: () => import("@/views/platformData/RecordRecharge/index"),
        meta: {
          title: "充值明细",
          icon: "list",
          aCode: "/platformData/RecordRecharge",
        },
      },
      {
        path: "CountWithdrawal",
        name: "CountWithdrawal",
        component: () => import("@/views/platformData/CountWithdrawal/index"),
        meta: {
          title: "用户提现日统计",
          icon: "list",
          aCode: "/platformData/CountWithdrawal",
        },
      },
      {
        path: "RecordWithdrawal",
        name: "RecordWithdrawal",
        component: () => import("@/views/platformData/RecordWithdrawal/index"),
        meta: {
          title: "提现明细",
          icon: "list",
          aCode: "/platformData/RecordWithdrawal",
        },
      },
      {
        path: "TotalIncome",
        name: "TotalIncome",
        component: () => import("@/views/platformData/TotalIncome/index"),
        meta: {
          title: "总收益日统计",
          icon: "list",
          aCode: "/platformData/TotalIncome",
        },
      },
      {
        path: "CountIncome",
        name: "CountIncome",
        component: () => import("@/views/platformData/CountIncome/index"),
        meta: {
          title: "用户收益日统计",
          icon: "list",
          aCode: "/platformData/CountIncome",
        },
      },
      {
        path: "RecordIncome",
        name: "RecordIncome",
        component: () => import("@/views/platformData/RecordIncome/index"),
        meta: {
          title: "收益明细",
          icon: "list",
          aCode: "/platformData/RecordIncome",
        },
      },
    ],
  },
  // 用户管理
  {
    path: "/Users",
    component: Layout,
    meta: { title: "用户管理", icon: "yhlb", aCode: "/Users" },
    children: [
      {
        path: "UserList",
        name: "UserList",
        component: () => import("@/views/Users/UserList/index"),
        meta: { title: "用户列表", icon: "user", aCode: "/Users/UserList" },
      },
      {
        path: "Team",
        name: "Team",
        component: () => import("@/views/Users/Team/index"),
        meta: { title: "服务商关系", icon: "list", aCode: "/Users/Team" },
      },
      {
        path: "Reticulum",
        name: "Reticulum",
        component: () => import("@/views/Users/Reticulum/index"),
        meta: { title: "网体业绩", icon: "list", aCode: "/Users/Reticulum" },
      },
      {
        path: "balance",
        name: "balance",
        component: () => import("@/views/Users/balance/index"),
        meta: { title: "用户余额列表", icon: "list", aCode: "/Users/balance" },
      },
      {
        path: "withdrawal",
        name: "withdrawal",
        component: () => import("@/views/Users/withdrawal/index"),
        meta: {
          title: "提现审核列表",
          icon: "list",
          aCode: "/Users/withdrawal",
        },
      },
      {
        path: "BalanceRecord",
        name: "BalanceRecord",
        component: () => import("@/views/Users/BalanceRecord/index"),
        meta: {
          title: "资金记录",
          icon: "user",
          aCode: "/Users/BalanceRecord",
        },
      },
      {
        path: "Feedback",
        name: "Feedback",
        component: () => import("@/views/Users/Feedback/index"),
        meta: { title: "意见反馈", icon: "list", aCode: "/Users/Feedback" },
      },
      {
        path: "rewardDaytatal",
        name: "rewardDaytatal",
        component: () => import("@/views/Users/rewardDaytatal/index"),
        meta: { title: "奖励记录日统计", icon: "list", aCode: "/Users/rewardDaytatal" },
      },
      {
        path: "rewardRecord",
        name: "rewardRecord",
        component: () => import("@/views/Users/rewardRecord/index"),
        meta: { title: "奖励记录", icon: "list", aCode: "/Users/rewardRecord" },
      },
      {
        path: "IncomeTotal",
        name: "IncomeTotal",
        component: () => import("@/views/Users/IncomeTotal/index"),
        meta: { title: "用户收入统计", icon: "list", aCode: "/Users/IncomeTotal" },
      },
    ],
  },
  // 商品管理
  {
    path: "/Goods",
    component: Layout,
    meta: { title: "商品管理", icon: "el-icon-s-shop", aCode: "/Goods" },
    children: [
      {
        path: "GoodsList",
        name: "GoodsList",
        component: () => import("@/views/Goods/GoodsList/index"),
        meta: { title: "商品列表", icon: "list", aCode: "/Goods/GoodsList" },
      },
      {
        path: "GoodsType",
        name: "GoodsType",
        component: () => import("@/views/Goods/GoodsType/index"),
        meta: { title: "商品类型", icon: "list", aCode: "/Goods/GoodsType" },
      },
      {
        path: "CouponList",
        name: "CouponList",
        hidden: true,
        component: () => import("@/views/Goods/CouponList/index"),
        meta: { title: "兑换券列表", icon: "list", aCode: "/Goods/CouponList" },
      },
      {
        path: "GoodsAttribute",
        name: "GoodsAttribute",
        hidden: true,
        component: () => import("@/views/Goods/GoodsAttribute/index"),
        meta: {
          title: "商品属性",
          icon: "list",
          aCode: "/Goods/GoodsAttribute",
        },
      },
      {
        path: "GoodsComment",
        name: "GoodsComment",
        hidden: true,
        component: () => import("@/views/Goods/GoodsComment/index"),
        meta: { title: "商品评论", icon: "list", aCode: "/Goods/GoodsComment" },
      },
    ],
  },
  // 订单管理
  {
    path: "/Orders",
    component: Layout,
    meta: { title: "订单管理", icon: "el-icon-s-shop", aCode: "/Orders" },
    children: [
      {
        path: "OrdersList",
        name: "OrdersList",
        component: () => import("@/views/Orders/OrdersList/index"),
        meta: { title: "订单列表", icon: "list", aCode: "/Orders/OrdersList" },
      },
      {
        path: "dayTotal",
        name: "dayTotal",
        component: () => import("@/views/Orders/dayTotal/index"),
        meta: { title: "订单日统计", icon: "list", aCode: "/Orders/dayTotal" },
      },
      {
        path: "totalMonth",
        name: "totalMonth",
        component: () => import("@/views/Orders/totalMonth/index"),
        meta: { title: "分红统计(月)", icon: "list", aCode: "/Orders/totalMonth" },
      },
    ],
  },
  // 资讯管理
  {
    path: "/News",
    component: Layout,
    meta: { title: "资讯管理", icon: "table", aCode: "/News" },
    children: [
      {
        path: "NewList",
        component: () => import("@/views/News/NewList/index"),
        name: "NewList",
        meta: { title: "资讯列表", icon: "list", aCode: "/News/NewList" },
      },
      {
        path: "GetTypes",
        component: () => import("@/views/News/Types/index"),
        name: "GetTypes",
        meta: {
          title: "资讯分类管理",
          icon: "el-icon-s-tools",
          aCode: "/News/GetTypes",
        },
      },
    ],
  },
  // 系统管理
  {
    path: "/SysConfig",
    component: Layout,
    meta: { title: "系统管理", icon: "el-icon-s-tools", aCode: "/SysConfig" },
    children: [
      {
        path: "GetPage",
        name: "GetPage",
        component: () => import("@/views/SysConfig/GetPage/index"),
        meta: {
          title: "系统配置",
          icon: "el-icon-s-tools",
          aCode: "/SysConfig/GetPage",
        },
      },
      {
        path: "Coin",
        name: "Coin",
        hidden: true,
        component: () => import("@/views/SysConfig/Coin/index"),
        meta: { title: "币种管理", icon: "list", aCode: "/SysConfig/Coin" },
      },
      {
        path: "GetSysUserLogs",
        name: "GetSysUserLogs",
        component: () => import("@/views/SysConfig/GetSysUserLogs/index"),
        meta: {
          title: "操作日志",
          icon: "el-icon-tickets",
          aCode: "/SysConfig/GetSysUserLogs",
        },
      },
      {
        path: "GetSysLogstb",
        name: "GetSysLogstb",
        component: () => import("@/views/SysConfig/GetSysLogstb/index"),
        meta: {
          title: "错误日志",
          icon: "el-icon-tickets",
          aCode: "/SysConfig/GetSysLogstb",
        },
      },
      {
        path: "UserLevelConfig",
        name: "UserLevelConfig",
        component: () => import("@/views/SysConfig/UserLevelConfig/index"),
        meta: {
          title: "会员等级管理",
          icon: "el-icon-s-tools",
          aCode: "/SysConfig/UserLevelConfig",
        },
      },
      {
        path: "DlsConfig",
        name: "DlsConfig",
        component: () => import("@/views/SysConfig/DlsConfig/index"),
        meta: {
          title: "服务商身份管理",
          icon: "el-icon-s-tools",
          aCode: "/SysConfig/DlsConfig",
        },
      },
    ],
  },
  // 权限管理
  {
    path: "/Sys",
    component: Layout,
    meta: { title: "权限配置", icon: "password", aCode: "/Sys" },
    children: [
      {
        path: "Auth",
        name: "Auth",
        component: () => import("@/views/sys/Auth/index"),
        meta: { title: "菜单模块管理", icon: "list", aCode: "/sys/Auth" },
      },
      {
        path: "Role",
        name: "Role",
        component: () => import("@/views/sys/Role/index"),
        meta: { title: "角色管理", icon: "theme", aCode: "/sys/Role" },
      },
      {
        path: "SysUsers",
        name: "SysUsers",
        component: () => import("@/views/sys/SysUsers/index"),
        meta: { title: "系统用户", icon: "user", aCode: "/sys/SysUsers" },
      },
    ],
  },
  // 404页面必须放在最后!!!
  { path: "*", redirect: "/404", hidden: true, meta: { parten: true } },
];

const createRouter = () =>
  new Router({
    scrollBehavior: () => ({ y: 0 }),
    routes: constantRoutes,
  });
const router = createRouter();
export function resetRouter() {
  const newRouter = createRouter();
  router.matcher = newRouter.matcher; // reset router
}

export default router;
